<?php
// Forumulär för upploaddning

// Feedback

// Visa lista med alla filer som länkar
class FileUploadView {
	public function createFileUploadForm() {
		// Fixa variablerna
		$uploadForm = "<form action='' method='post'
				enctype='multipart/form-data'>
				<label for='file'>Filnamn:</label>
				<input type='file' name='file' id='file' /> 
				<br />
				<input type='submit' name='upload' value='upload' />
				</form>";
		return $uploadForm;
	}

	public function showFeedback($action) {
		// Returns passed value enclosed by paragraph tags, if error is set to true then add classname error, else feedback.	
		$msg = "<p class='feedback'>$action</p>";
		return $msg;
	}

	public function listFiles() {
		$fileUploadHandler = new FileUploadHandler();
		$fileList = "<h2>Uppladdade filer</h2><ul>";
		$fileDir = $fileUploadHandler -> dir;
		$files = $fileUploadHandler -> getFiles();
		if (sizeof($files) == 2) {
			$fileList .= "<li>Inga filer har laddats upp ännu</li>.";
		} else {
			foreach ($files as $file) {
				// List all files in directory as links
				if ($file != '.' && $file != '..') {
					$fileList .= "<li><a href='$fileDir/$file'>$file</a></li>";
				}
			}
		}
		return $fileList;
	}

	public function triedToUpload() {
		// Returns true if upload button has been clicked
		if (isset($_POST['upload'])) {
			return true;
		}
		// else return false
		else {
			return false;
		}
	}

}
?>